package com.css.fxfzcpxx.base.attachment.repository.impl;

import com.css.fxfzcpxx.base.attachment.entity.AttachmentRecordEntity;
import com.css.fxfzcpxx.base.attachment.repository.AttachmentRecordRepository;
import com.css.fxfzcpxx.base.attachment.service.AttachmentRecordService;
import com.css.fxfzcpxx.util.UUIDGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Author:
 * @CreateTime: 2023/9/12 11:02
 * @Description:
 */
@Service
public class AttachmentRecordServiceImpl implements AttachmentRecordService {
    @Autowired
    private AttachmentRecordRepository attachmentRecordRepository;

    @Override
    public AttachmentRecordEntity findByAttachmentId(String attachId) {
        return attachmentRecordRepository.findByAttachmentId(attachId);
    }

    @Override
    public void update(String id, Integer downloadCount) {
        attachmentRecordRepository.update(id,downloadCount);
    }

    @Override
    public void save(String attachId) {
        AttachmentRecordEntity attachmentRecord = new AttachmentRecordEntity();
        attachmentRecord.setAttachmentId(attachId);
        attachmentRecord.setId(UUIDGenerator.getUUID());
        attachmentRecord.setDownloadTime(new Date());
        attachmentRecord.setDownloadCount(1);
        attachmentRecordRepository.save(attachmentRecord);
    }
}
